package cn.cvs.service;

import cn.cvs.mapper.UserMapper;
import cn.cvs.pojo.SysUser;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserServiceImpl implements UserService{
    @Resource
    UserMapper userMapper;

    @Override
    public SysUser doLogin(String username
            , String password) {
        SysUser user = userMapper.findByUsrName(username);
        if (null != user){
            if (password.equals(user.getUsrPassword()))
            return user;
        }
        return null;
    }


    @Cacheable(keyGenerator = "keyGenerator", value = "user")
    @Override
    public List<SysUser> findAll() {
        return userMapper.findAll();
    }

    @Override
    public void addUser(SysUser user) {
        userMapper.insert(user);
    }

    @Override
    public SysUser getUserByName(String usrName) {
        return  userMapper.findByUsrName(usrName);
    }

    @Override
    public SysUser findRoleByUsrName(String userName) {
        return userMapper.findRoleByUsrName(userName);
    }

}
